﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System;
using DTO;
using System.Data.OleDb;

namespace DAO
{
    public class LoaiSachDAO
    {
        public static DataTable layFullLoaiSach()
        {
            List<LoaiSachDTO> lst = new List<LoaiSachDTO>();
            String strQuery = "select * from LoaiSach where chXoa = 0";
            OleDbConnection con = DataProvider.conectDB();
            OleDbCommand cmd = new OleDbCommand(strQuery, con);
            OleDbDataReader reader = cmd.ExecuteReader();
            DataTable table = new DataTable();
            table.Load(reader);
            reader.Close();
            con.Close();
            return table;
        }
        public static Boolean themLoaiSach(LoaiSachDTO ls)
        {
            String strQuery = "insert into [LoaiSach]";//values('{0}','{1}','null','{2}','{3}',0)",ls.TenLoaiSach,ls.TienTo,ls.ChiTiet,ls.Thue);
            strQuery += "(tenLoaiSach,tienTo,chiTiet,thueVAT,chXoa)";
            strQuery += String.Format("values('{0}','{1}','{2}','{3}',0)", ls.TenLoaiSach, ls.TienTo, ls.ChiTiet, ls.Thue);
            return DataProvider.ExcuteNonQuery(strQuery);
        }
        public static Boolean xoaLoaiSach(int id)
        {
            String strQuery = String.Format("update [LoaiSach] set [chXoa]= 1 where [id] = {0}", id);
            return DataProvider.ExcuteNonQuery(strQuery);
        }
        public static Boolean updateLoaiSach(LoaiSachDTO ls)
        {
            String strQuery = "update [LoaiSach]";
            strQuery += String.Format("set [tenLoaiSach] = '{0}', [tienTo] = '{1}', [maSachCapNhat]='{2}', [chiTiet]='{3}', [thueVAT] = {4} ",ls.TenLoaiSach, ls.TienTo,ls.MaSachCapNhat,ls.ChiTiet,ls.Thue);
            strQuery += String.Format("where [id] = {0}", ls.Id);
            return DataProvider.ExcuteNonQuery(strQuery);
        }
        public static DataTable timKiem(String sql)
        {
            OleDbConnection con = DataProvider.conectDB();
            OleDbCommand cmd = new OleDbCommand(sql, con);
            OleDbDataReader reader = cmd.ExecuteReader();
            DataTable table = new DataTable();
            table.Load(reader);
            reader.Close();
            con.Close();
            return table;
        }
    }
}
